/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/



#pragma once
#include "gdipisapi.h"

/*!
 \defgroup PGLISAPIGroup ISAPI extenstion dll helpers
 \ingroup PGLGroup
*/

/*! \brief A wrapper for ISAPI extensions

Use this object to render a CPGLRegion object to the client browser.

\par Writing chart to client

  Just use the function #WriteRegion . Do not add headers since they are set internally.

\par Output types

  There are 4 output types: 
	- PNG, portable network graphics, 
	- JPEG, 
	- BMP, windows bitmap,
	-SVG, scalable vector graphics
	
  These output types are enumerated in the EOutputType enumeration. 
  The output type is set with the constructor or with #SetOutputType method.

  The "raster" output types (PNG, JPEG, BMP) can be called via the following html code:
\code
<img src="YourISAPIExtension.dll?Raster"/>
\endcode

  The vectorial output type (SVG) can be called via the following html code:
\code
<embed src="YourISAPIExtension.dll?Raster"/>
\endcode

\par Dimensions
	You can modify the width and height of the output with #SetDimensions.

\par Multi Threading
  In order to be thread safe, create a new CPGLISAPIRenderer object at each function call.


\ingroup PGLISAPIGroup
*/
class CPGLISAPIRenderer : public CGDIpISAPI
{
public:
	//! Ouput types
	enum EOutputType
	{
		//! PNG
		OutputPNG=0,
		//! JPG
		OutputJPG=1,
		//! BMP
		OutputBMP=2,
		//! SVG
		OutputSVG=3
	};

public:

	//! \name Constructors
	//@{
	/*! \brief Constructor
	  
	  \param pServer pointer to the CHttpServer class
	  \param pCtxt pointer to the CHttpServerContext object
	  \param pImage pointer to a GDI+ image object
	  \param pRegion pointer to PGL region to plot
	  \param eImageType image type (default is PNG)
	  \param ulQuality quality. Applies to PNG and JPEG (default is 80)	  
	  */
	CPGLISAPIRenderer(CHttpServer* pServer=NULL, 
		CHttpServerContext* pCtxt=NULL,
		CPGLRegion* pRegion=NULL,
		UINT uWidth=320, 
		UINT uHeight=200, 
		EOutputType eOutputType = OutputPNG)
		: CGDIpISAPI(pServer, pCtxt, NULL), m_pRegion(pRegion),m_dim(0,0)
	{
		SetOutputType(eOutputType);
		SetDimensions(uWidth,uHeight);
	};
	virtual ~CPGLISAPIRenderer()
	{
		if (m_pImage)
			delete m_pImage;
	};
	//@}


	//! sets the output type
	void SetOutputType( EOutputType eOutputType);
	//! returns current output type
	EOutputType GetOutputType() const				{	return m_eOutputType;};
	//! sets dimensions
	void SetDimensions( UINT uWidth, UINT uHeight);
	//! return width
	UINT GetWidth() const							{	return m_dim.x;};
	//! return width
	UINT GetHeight() const							{	return m_dim.y;};

	//! \name Setters and getters
	//@{
	//! Sets region object
	void SetRegion(CPGLRegion* pRegion)		{	m_pRegion = pRegion;};
	//! return region object
	CPGLRegion* GetRegion()					{	return m_pRegion;};
	//@}

	//! \name Output function
	//@{
	void WriteRegion();
	//@}

protected:

	//! \name Output function
	//@{
	//! Raster region to client browser as JPEG, BMP or PNG
	void WriteRegionAsImage();
	//! WriteRegion as SVG
	void WriteRegionAsSVG();
	//@}

	CPGLPointU m_dim;
	EOutputType m_eOutputType;
	CPGLRegion* m_pRegion;
	static UINT m_stuMaxWidth;
	static UINT m_stuMaxHeight;
};
